package cn.edu.scau.cmi.xiaowenyang.client;

import cn.edu.scau.cmi.xiaowenyang.factoryMethod.CarBrokenInsuranceFactory;
import cn.edu.scau.cmi.xiaowenyang.factoryMethod.CasualtyInsurance;
import cn.edu.scau.cmi.xiaowenyang.factoryMethod.CasualtyInsuranceFactory;
import cn.edu.scau.cmi.xiaowenyang.factoryMethod.DriverInjuryInsuranceFactory;
import cn.edu.scau.cmi.xiaowenyang.factoryMethod.Factory;
import cn.edu.scau.cmi.xiaowenyang.staticFactoryMethod.CarBrokenInsurance;
import cn.edu.scau.cmi.xiaowenyang.staticFactoryMethod.DriverInjuryInsurance;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class FactoryMethodClient extends Application {
	public static void main(String[] args) {
		launch(args);
	}

	String type = new String("司机受伤");
	Factory carBrokenInsuranceFactory = new CarBrokenInsuranceFactory();
	Factory casualtyInsuranceFactory = new CasualtyInsuranceFactory();
	Factory driverInjuryInsuranceFactory = new DriverInjuryInsuranceFactory();

	@Override
	public void start(Stage primaryStage) throws Exception {
		primaryStage.setTitle("工厂方法");
		Pane pane = new Pane();
		Button button = new Button("显示保险信息");
		TextArea textArea = new TextArea();
		Label label1 = new Label("姓名 ：肖文洋     学号：201627020121");
		Label label2 = new Label("请选择保险");
		ImageView imageView = new ImageView();
		ComboBox<String> comboBox = new ComboBox<>();
		comboBox.setEditable(true);
		comboBox.getItems().addAll("司机受伤", "汽车损坏", "人员伤亡");
		comboBox.getSelectionModel().select(0);

		comboBox.valueProperty().addListener(new ChangeListener<String>() {
			@Override
			public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
				// TODO Auto-generated method stub
				type = newValue;
			}
		});

		button.setOnMouseClicked(new EventHandler<MouseEvent>() {
			@Override
			public void handle(MouseEvent event) {
				// TODO Auto-generated method stub
				String str = "";
				switch (type) {
				case "司机受伤":
					str = driverInjuryInsuranceFactory.getInsurance().getInsuranceMessage();
					break;
				case "汽车损坏":
					str = carBrokenInsuranceFactory.getInsurance().getInsuranceMessage();
					break;
				case "人员伤亡":
					str = casualtyInsuranceFactory.getInsurance().getInsuranceMessage();
					break;
				}
				textArea.setText(str);
			}

		});

		imageView.setImage(new Image("01.png", 300, 0, true, true));
		imageView.setLayoutX(0);
		imageView.setLayoutX(10);

		label1.setFont(new Font(20));
		label1.setLayoutX(350);
		label1.setLayoutY(10);

		label2.setFont(new Font(15));
		label2.setLayoutX(350);
		label2.setLayoutY(100);

		comboBox.setLayoutX(450);
		comboBox.setLayoutY(100);

		button.setLayoutX(500);
		button.setLayoutY(200);

		textArea.setPrefHeight(400);
		textArea.setPrefWidth(1000);
		textArea.setLayoutX(0);
		textArea.setLayoutY(300);
		textArea.setEditable(false);

		pane.getChildren().addAll(textArea, button, label1, label2, imageView, comboBox);

		primaryStage.setScene(new Scene(pane, 1000, 700));
		primaryStage.show();
	}
}
